// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/video/api/CamerasApi'

import InfoClass from '@api/video/model/CamerasPreviewReq'

const CLIENT = CORE.grpcCLIENT(Client)

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 信息 —————————————————————————————— //

  async getInfo({ id }, TIP = '信息') {
    if (!id) return {}
    const DTO = CORE.grpcDTO(InfoClass, { cameraId: id })
    const { content = {}, thirdCode } = await CORE.grpc(TIP, CLIENT, 'camerasPreviewUrls', DTO)
    return { ...content, thirdCode }
  },
  transInfo(obj = {}) {
    const get = (key) => (obj[key] || '').replace('localhost', '192.168.139.101')
    return {
      ws_mp4: get('wsFmp4'),
      ws_flv: get('wsFlv'),
      ws_ts: get('wsTs'),
      ws_m3u8: get('wsHls'),

      wss_mp4: get('wssFmp4'),
      wss_flv: get('wssFlv'),
      wss_ts: get('wssTs'),
      wss_m3u8: get('wssHls'),

      http_mp4: get('fmp4'),
      http_flv: get('flv'),
      http_ts: get('ts'),
      http_m3u8: get('hls'),

      https_mp4: get('httpsFmp4'),
      https_flv: get('httpsFlv'),
      https_ts: get('httpsTs'),
      https_m3u8: get('httpsHls'),

      rtc: get('rtc'),
      rtmp: get('rtmp'),
      rtmps: get('rtmps'),
      rtsp: get('rtsp'),
      rtsps: get('rtsps'),

      thirdCode: get('thirdCode'),
    }
  },
}
